﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Serialization;

namespace Scrobbler.Utils
{
    public class Deserializer<T>
    {
        public static T DeserializeXml(string xmlDocument)
        {
            var xmlSerializer = new XmlSerializer(typeof(T));
            using (var xr = XmlReader.Create(new StringReader(xmlDocument), new XmlReaderSettings { CheckCharacters = false }))
            {
                return (T)xmlSerializer.Deserialize(xr);
            }
        }

        public static T DeserializeJson(string jsonDocument)
        {
            return new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize<T>(jsonDocument);
        }
    }
}
